 using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data;
using Zhuang.DAL;
using System.Configuration;
using System.Web.Services.Protocols;

namespace Zhuang.WebService
{
    /// <summary>
    /// ZhuangDbService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class ZhuangDbService : System.Web.Services.WebService
    {

        Sys_ProductDAL sys_ProductDAL = new Sys_ProductDAL();


        public MySoapHeader mySoapHeader;


        
        public ZhuangDbService()
        {
            GlobalDAL.SetConnectingString(ConfigurationManager.ConnectionStrings["ZhuangDb"].ConnectionString);
        
        }


        //验证是否合法 
        private void VerifyCredential(ZhuangDbService s)
        {
            if (s.mySoapHeader == null || s.mySoapHeader.UserName != "zwb" || s.mySoapHeader.UserPassword!= "123")
            {
                throw new SoapException("验证失败", SoapException.ClientFaultCode, "Security");
            }
            //在这里可以进一步进行自定义的用户验证 
        }

        [System.Web.Services.Protocols.SoapHeader("mySoapHeader")]//用户身份验证的soap头
        [WebMethod(Description = "Hello World")]
        public string HelloWorld()
        {
            //VerifyCredential(this);
            return "Hello World";
        }

        [System.Web.Services.Protocols.SoapHeader("mySoapHeader")]//用户身份验证的soap头
        [WebMethod]
        public DataSet Sys_GetUpdatedProduct(string beginDate)
        {
            VerifyCredential(this);

            return sys_ProductDAL.GetUpdatedProduct(beginDate);
        }
    }
}